#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTime>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    QPixmap *pix = new QPixmap();
    pix->load("E:\\qt_workspace\\img\\rabbit.png");

    ui->pictureLabel->setPixmap(*pix);
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_startButton_clicked()
{
    myTimerId = this->startTimer(1000);
}

void MainWindow::timerEvent(QTimerEvent *event)
{
    qInfo("timer");

    if(event->timerId() != myTimerId) return;

    qInfo("timer2");

    QString path("E:\\qt_workspace\\img\\");

    qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    path += (qrand() % 2 == 0 ? "nangua.jpeg" : "rabbit.png");

    qInfo(path.toStdString().c_str());

    QPixmap *pix = new QPixmap();
    pix->load(path);
    ui->pictureLabel->setPixmap(*pix);
}

void MainWindow::on_stopButton_clicked()
{
    this->killTimer(myTimerId);
}
